/*
 * Created by: Peter Weissbrod
 * Created: Monday, January 21, 2008
 */
using System;
using System.Reflection;

namespace PostSharp.UserSamples.Utils
{
    public class CompileTimeValidateScenario
    {
        /// <summary>
        /// The criteria for public property setter methods
        /// </summary>
        /// <param name="methodBase"></param>
        /// <returns></returns>
        public static bool ValidateForPublicPropertySetter(MethodBase methodBase)
        {
            if (!methodBase.IsPublic)
                return false;
            if (!methodBase.Name.StartsWith("set_"))
                return false;
            return true;
        }
        /// <summary>
        /// The criteria to restrict an attribute to a specific type at compile time
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool RestrictPropertySetterToSpecificType(MethodBase methodBase,Type type)
        {
            if (methodBase.GetParameters() == null)
                return false;
            if (methodBase.GetParameters().Length != 1)
                return false;
            return methodBase.GetParameters()[0].ParameterType == type;
        }
    }
}